# 1多窗口操作

# from time import sleep
#
# from selenium import webdriver
# from  selenium.webdriver.common.by import By
#
# l = webdriver.Edge()
# l.get("http:www.baidu.com")
# sleep(2)
#
# # 打开多个窗口
# a = l.find_elements(By.CLASS_NAME,"mnav.c-font-normal.c-color-t")
# for i in a:
#     i.click()
#     # sleep(1)
# # 获取所有窗口信息
# ls = l.window_handles
# for j in ls:
#     print(j)
# # 获取当前窗口信
# b = l.current_window_handle
# print(b)
# print(l.title)
# # 切换窗口
# c = l.switch_to.window(ls[2])
# print(l.current_window_handle)
# print(l.title)

# # 2iframe操作
#
# import time
#
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.select import Select
#
# l = webdriver.Edge()
# l.get("http://127.0.0.1/ranzhi/www/")
# time.sleep(3)
# # 2)点击登陆按钮
# l.find_element(By.ID,"account").send_keys("admin")
# l.find_element(By.ID,"password").send_keys("123456")
# l.find_element(By.ID,"submit").click()
# time.sleep(5)
# # 3)点击后台管理按钮
# button1 = l.find_element(By.XPATH,"/html/body/div[1]/div[1]/div/ul[1]/li[8]/button").click()
# time.sleep(2)
#
# # 切换到iframe
# # 定位iframe
# iframe = l.find_element("id","iframe-superadmin")
# l.switch_to.frame(iframe)
# # 点击添加成员
# l.find_element("class name","shortcut.user").click()
# time.sleep(2)
#
# # 3下拉框
#
# # 角色下拉框
# role = l.find_element("id","role")
# # 强转为select对象
# s = Select(role)
# # 获取所有的下拉选项的对象
# ls = s.options
# lstext = []
# for i in ls:
#     lstext.append(i.text)
# print(lstext)
# # 选中对象
# # s.select_by_index(1)
# s.select_by_value("pm")
# # s.select_by_visible_text(lstext[3])
# time.sleep(4)
# # 切换到上一层
# # l.switch_to.default_content()
# # driver.switch_to.parent_frame()
# l.back()
# time.sleep(2)
# #点击签退
# l.find_element("class name","sign.signout").click()
# time.sleep(4)
#
# 4弹出框

# import time
#
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.select import Select
#
# driver = webdriver.Edge()
# driver.get("http://127.0.0.1/ranzhi/www/")
# time.sleep(2)
#
# # 用户名密码
# driver.find_element("xpath",'//*[@id="account"]').send_keys("admin")
# driver.find_element("xpath",'//*[@id="password"]').send_keys("123456")
# time.sleep(2)
# # 点击登录
# driver.find_element("xpath",'//*[@id="submit"]').click()
# time.sleep(2)
# # 点击文档
# driver.find_element("id","s-menu-4").click()
# time.sleep(2)
# # 切换到iframe
# driver.switch_to.frame(driver.find_element("id","iframe-4"))
# time.sleep(2)
# # 点击其中一个文档库
# driver.find_element("class name","libs-group-heading.libs-custom-heading").click()
# time.sleep(2)
# # 点击创建文档
# driver.find_element("class name","btn.btn-primary").click()
# time.sleep(2)
# # 选择文件 大文件
# a = driver.find_element("name","files[]")
# a.send_keys("d:\\基于STM32的智能路灯设计与实现 .zip")
# # 切换到提示框
# alter1 = driver.switch_to.alert
# time.sleep(2)
# # 获取提示框的文本信息
# print(alter1.text)
# # 提示框的确认
# alter1.accept()
# time.sleep(4)
# # 切换到上一层
# driver.switch_to.default_content()
# # driver.switch_to.parent_frame()
# # 点击签退
# driver.find_element("class name","sign.signout").click()
# time.sleep(4)

# 5执行javascript代码

# import time
#
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.select import Select
#
# driver = webdriver.Edge()
# driver.get("http://www.baidu.com")
# time.sleep(1)
# # 修改窗口的大小
# driver.set_window_size(600,500)
# time.sleep(3)
# # 向右100px
# driver.execute_script("window.scrollTo(100,0)")
# time.sleep(3)
# # 向下200px
# driver.execute_script("window.scrollTo(100,200)")
# time.sleep(3)
# # 滑动到最右边
# driver.execute_script("window.scrollTo(document.body.scrollWidth,200)")
# time.sleep(3)
# # 滑动到最下边
# driver.execute_script("window.scrollTo(document.body.scrollWidth,document.body.scrollHeight)")
# time.sleep(1)
# # 切换到然知系统
# driver.get("http://127.0.0.1/ranzhi/www")
# time.sleep(3)
# input1 = driver.find_element("id","account")
# driver.execute_script("arguments[0].setAttribute('style','display:none');",input1)
# time.sleep(3)
# try:
#     input1.send_keys("admin")
# except Exception as e:
#     print(e)
# # driver.execute_script("arguments[0].setAttribute('style','display:block');",input1)
# driver.execute_script("arguments[0].removeAttribute('style','display:none');",input1)
# time.sleep(3)

# 6三种等待

# import time
#
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support import expected_conditions
# from selenium.webdriver.support.select import Select
# from selenium.webdriver.support.wait import WebDriverWait
#
# driver = webdriver.Edge()
# driver.get("http://www.baidu.com")
# # driver.implicitly_wait(10)  #隐式等待
# # driver.find_element("id","chat-textarea").send_keys("测试内容")
# # 显式等待
# locator = ("id","chat-textarea")
# input1 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator))
# input1.send_keys("显式等待")
#
# time.sleep(10)

# 7截屏

import time


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Edge()
driver.get("http://www.baidu.com")
time.sleep(3)
# 获取一个时间字符串
timestr = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime())
driver.get_screenshot_as_file(f"d:\\baidu{timestr}.png")
time.sleep(3)


